<html lang="en">
<head>
    <title>推荐专题管理</title>
    <#include "../common/header.ftl"/>
    <#include "../common/page.ftl"/>
    <script type="text/javascript" src="/js/plugins/jquery.form.js"></script>


    <script>
        $(function () {
            //图片更换回显
            $('#editForm input[name="file"]').change(function () {
                $('#editForm img').attr('src',window.URL.createObjectURL(this.files[0]));
            });

            $(".inputBtn").click(function () {
                $("#editForm")[0].reset();
                $('#editForm img').attr('src','');
                var json = $(this).data("json");
                if(json){
                    $("#editForm input[name='id']").val(json.id);
                    $("#editForm input[name='detail.id']").val(json.did);
                    $("#editForm input[name='name']").val(json.name);
                    $("#editForm select[name='parent.id']").val(json.pid);
                    $("#editForm select[name='state']").val(json.state);

                    $("#editForm img").attr("src",json.dCoverUrl);
                    console.log(json.dCoverUrl);
                    $("#editForm input[name='detail.coverUrl']").val(json.dCoverUrl);
                }
                $("#editModal").modal("show");
            });

            $(".submitBtn").click(function () {
                $("#editForm").ajaxSubmit(function (data) {
                    if(data.success){
                        $.messager.confirm("温馨提示","操作成功",function () {
                            window.location.reload();
                        })
                    }else{
                        $.messager.alert("温馨提示",data.msg);
                    }
                })
            });
        });
    </script>
</head>
<body>
<!--左侧菜单回显变量设置-->
<#assign currentMenu="specialSubCommend">

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-2">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-10">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">推荐专题管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/specialSubCommend/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label for="keyword">关键字:</label>
                    <input type="text" class="form-control" id="keyword" name="keyword" value="${qo.keyword!}" placeholder="请输入标题">
                </div>
                <button id="btn_query" class="btn btn-info"><span class="glyphicon glyphicon-search"></span> 查询</button>
                <a href="javascript:;" class="btn btn-success glyphicon-plus inputBtn" id="addSpecialSubCommendBtn"> 添加</a>
            </form>

            <table class="table table-striped table-hover" >
                <thead>
                    <tr>
                        <th>编号</th>
                        <th>推荐专题</th>
                        <th>所属大分类</th>
                        <th>状态</th>
                        <th>图片</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <#list result.list as entity>
                   <tr>
                       <td>${entity_index+1}</td>
                       <td>${entity.name!}</td>
                       <td>${(entity.parent.name)!}</td>
                       <td>${entity.stateDispaly!}</td>
                       <td><img src="${(entity.detail.coverUrl)!}" width="60px"></td>
                       <td>
                           <a href="javscript:;" class="btn inputBtn" data-json='${entity.jsonString}'>修改</a>
                       </td>
                   </tr>
                </#list>
            </table>
            <div style="text-align: center;">
                <ul id="pagination" class="pagination"></ul>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">编辑/增加</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/specialSubCommend/saveOrUpdate.do" method="post" id="editForm" enctype="multipart/form-data">
                    <input type="hidden" value="" name="id">
                    <input type="hidden" value="" name="detail.id">
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">推荐专题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name" value="" placeholder="请输入推荐标题">
                        </div>
                    </div>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">所属大分类：</label>
                        <div class="col-sm-6">
                            <select name="parent.id" class="form-control" id="parent">
                                <option value="-1">--请选择--</option>
                                <#list bigs as p>
                                    <option value="${p.id}">${p.name}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">状态：</label>
                        <div class="col-sm-6">
                            <select name="state" class="form-control" id="state">
                                <option value="0">普通分类专题</option>
                                <option value="2">推荐页面专题</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img src="" width="200px">
                            <input type="file" name="file">
                            <input type="hidden" name="detail.coverUrl" value="">
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary submitBtn">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal" >取消</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>